$(function() {
	$("#registerFrm").validate({
		rules: {
	        first_name: {
	          required: true,
	          defultNone: true
	        },
	        last_name: {
	          required: true,
	          defultNone: true	          
	        },
	        email: {
	          required: true,
	          email:true,
	          defultNone: true
	        },	
	        password: {
	          required: true,
	          defultNone: true
	        },	
	        repassword: {
	          required: true,
			  equalTo: "#password",
			  defultNone: true
	        },				
		}
	});
	
	$("#myaccountFrm").validate({
		rules: {
	        first_name: {
	          required: true
	        },
	        last_name: {
	          required: true
	        },
	        email: {
	          required: true,
	          email:true
	        },	
	        password: {
	          required : function(){ return ($("#current_pass").val().length)? true : false}
	        },	
	        repassword: {
	          required : function(){ return ($("#current_pass").val().length)? true : false},
			  equalTo: "#password"
	        }			
		}
	});
	
	 $.validator.addMethod("valueNotEquals", function(value, element, arg){
	  return arg != value;
	 }, (lang.form_required_field != undefined) ? lang.form_required_field : '[form_required_field]');	
	
	$("#myaddressFrm").validate({
		rules: {
	        first_name: {
	          required: true
	        },
	        last_name: {
	          required: true
	        },
	        tax_number: {
	          required : function(){ return ($("#company").val().length)? true : false}
	        },			
	        tel: {
	          required: true
	        },
	        street: {
	          required: true
	        },
	        zip: {
	          required: true
	        },
	        city: {
	          required: true
	        },
	        country_id: {
	          valueNotEquals: 0
	        }			
		}
	});	
	
	$('#btn-send').click(function(){
		if ($("#registerFrm").valid()){
			$('#registerFrm').submit();
		}
	});
	
	$('#btn-save').click(function(){
		if ($("#myaccountFrm").valid()){
			$('#myaccountFrm').submit();
		}
	});
	
	$('#btn-save-address').click(function(){
		if ($("#myaddressFrm").valid()){
			$('#myaddressFrm').submit();
		}
	});	

	$('#current_pass').blur(function(){
		if ($(this).val().length) {
			$('.passwords .required').removeClass('hidden');
		}
		else {
			$('.passwords .required').addClass('hidden');
		}
	});
	$('#company').blur(function(){
		if ($(this).val().length) {
			$('.hiddens .required').removeClass('hidden');
		}
		else {
			$('.hiddens .required').addClass('hidden');
		}
	});	
});